package com.face.server.convert;

import com.face.server.dao.JoinedDAO;
import com.face.server.entity.DormitoryAdmin;
import com.face.server.entity.EventLog;
import com.face.server.vo.DormAdminEvent;
import com.face.server.vo.VisitorEvent;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by ryan on 2018/4/12.
 */
@Component
public class Event2DormAdminEvent {
    @Autowired
    JoinedDAO joinedDAO;
    public DormAdminEvent convert(EventLog eventLog){
        DormAdminEvent dormAdminEvent=new DormAdminEvent();
        BeanUtils.copyProperties(eventLog,dormAdminEvent);
        DormitoryAdmin dormitoryAdmin=joinedDAO.findDormAdminByName(eventLog.getName());
        String job=null;
        if (dormitoryAdmin==null||dormitoryAdmin.getJobName()==null)
            job="";
        else
            job=dormitoryAdmin.getJobName();
        dormAdminEvent.setJob(job);
        return dormAdminEvent;
    }

    public List<DormAdminEvent> convert(List<EventLog> eventLogs){
        return eventLogs.stream().map(e->convert(e)).collect(Collectors.toList());
    }
}
